<template>
	<div class="crumbs">
	    <el-breadcrumb separator="/">
	        <el-breadcrumb-item><i class="el-icon-lx-calendar"></i>投资管理</el-breadcrumb-item>
			<el-breadcrumb-item>投资代数</el-breadcrumb-item>
	    </el-breadcrumb>
		<el-table
		 :data="algebra"
		 border
		 style="width: 100%">
			 <el-table-column
			  align="center"
			   prop="level"
			   label="代数"
			   width="60">
			 </el-table-column>
			 
			 <el-table-column
			  align="center"
			   prop="child_num"
			   label="直推人数"
			   width="140">
			 </el-table-column>
			 
			
			 <el-table-column
			  align="center"
				prop="pintuan"
				label="是否参加拼团"
				width="140">
				<template slot-scope="scope">
					<span>{{scope.row.pintuan?'是':'否'}}</span>
				</template>
			  </el-table-column>
			 
			 <el-table-column
			  align="center"
			   prop="rate"
			   label="比列"
			   width="140">
			 </el-table-column>
			 <el-table-column
			  align="center"
			   prop="invest_money"
			   label="合约累计金额"
			   width="140">
			   <template slot-scope="scope">
				   <span>
					   {{scope.row.invest_money?scope.row.invest_money:'无效'}}
				   </span>
			   </template>
			 </el-table-column>
			 <el-table-column
			     align="center"
				 width="80"
			 	label="操作">
			     <template slot-scope="scope">
			         <el-button type="text" icon="el-icon-document" @click="handalgebraEdit(scope.$index,scope.row)">
			 		修改
			 		</el-button>
			     </template>
			 </el-table-column>
		</el-table>
		 <el-button @click="baocunClick" type="primary" class="baoclick">保存修改</el-button>
		<el-dialog title="编辑" :visible.sync="editVisible" width="40%">
		    <el-form ref="form" :model="form" label-width="100px">
		        <el-form-item label="代数">
		            <el-input v-model="form.level"></el-input>
		        </el-form-item>
				<el-form-item label="直推人数">
				    <el-input v-model="form.child_num"></el-input>
				</el-form-item>
				<el-form-item label="是否参加拼团">
				    <el-switch v-model="form.pintuan"></el-switch>
				 </el-form-item>
		        <el-form-item label="比列">
		            <el-input v-model="form.rate"></el-input>
		        </el-form-item>
				<el-form-item label="合约累计金额">
				    <el-input v-model="form.invest_money"></el-input>
				</el-form-item>
		    </el-form>
		    <span slot="footer" class="dialog-footer">
		        <el-button @click="editVisible = false">取 消</el-button>
		        <el-button type="primary" @click="saveEdit()">确 定</el-button>
		    </span>
		</el-dialog>
	</div>
</template>

<script>
	export default{
		data(){
			return{
				algebra:[],
				editVisible:false,
				index:'',
				form:{
					id:'',
					level: '',
					rate:'',
					child_num:'',
					model_id:'',
					bonus_type:'',
					pintuan:'',
					invest_money:''
				}
			}
		},
		methods:{
			getAlgebra(){
				// let avatar = 
				let pram = {}
				this.$post_('trade/commodity/get-algebra',pram,(res) => {
					console.log(res.data)
				  this.algebra = res.data
				})
			},
			
			handalgebraEdit(index,row){
				console.log(row)
				this.editVisible = true
				this.index = index
				this.form.id = row.id
				this.form.bonus_type = row.bonus_type
				this.form.level = row.level
				this.form.rate = row.rate
				this.form.child_num = row.child_num
				this.form.pintuan = row.pintuan
				this.form.invest_money = row.invest_money;
			},
			saveEdit(){
				this.editVisible = false
				this.algebra.splice(this.index,1,this.form)
			},
			baocunClick(){
				// let arr = this.algebra.split(',')
				// console.log(arr)
				// let params = {
				// 	'data':JSON.stringify(this.algebra)
				// }
				console.log({'data':JSON.stringify(this.algebra)})
				this.$post_('trade/commodity/set-algebra', {'data':JSON.stringify(this.algebra)},res=>{
					console.log(res)
					if(res.code=='0'){
					    this.getAlgebra();
					    this.$message.success(res.msg);
					}else{
					    this.$message.success(res.msg);
					}
				})
			}
		},
		created(){
			this.getAlgebra()
		}
	}
</script>

<style>
	.baoclick{
		margin-top: 10px;
	}
</style>
